package com.example.xlmkotlinwanandroid.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.viewpager2.widget.ViewPager2
import com.example.xlmkotlinwanandroid.R
import com.example.xlmkotlinwanandroid.base.BaseActivity
import com.example.xlmkotlinwanandroid.databinding.ActivityWelcomeBinding
import com.example.xlmkotlinwanandroid.ui.adapter.WelcomePageAdapter

/**
 * android的引导页,该类中有3-5个引导页面对用户进行引导
 * 主要是采用viewpager来实现相关的逻辑，后期可以设置为可定制的
 */

class WelcomeActivity : BaseActivity() {

    private lateinit var welcomeBinding: ActivityWelcomeBinding
    private lateinit var welcomeList: List<Int>


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initData()
        initView()
    }

    override fun initView() {
        //获取总布局
        welcomeBinding =
            DataBindingUtil.setContentView<ActivityWelcomeBinding>(this, R.layout.activity_welcome)
        val welcomePageAdapter = WelcomePageAdapter()
        welcomePageAdapter.setDatas(welcomeList)
        welcomeBinding.vpRoot.adapter = welcomePageAdapter

        welcomeBinding.vpRoot.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                if (position ==3){
                    welcomeBinding.ivJump.setOnClickListener {
                        goMainActivity()
                    }
                }
            }
        })

    }

    //初始化数据
    private fun initData() {
        welcomeList =
            arrayListOf<Int>(R.drawable.welcome1, R.drawable.welcome2, R.drawable.welcome3,R.drawable.splashbackground)
    }
    private fun goMainActivity() {
        var intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
        finish()
    }

}